import os
import time
import ntplib


def GetNtpTime(ntp):
    try:
        c = ntplib.NTPClient()
        response = c.request(ntp)
        ts = int(response.tx_time) + 8*3600
        print(ts)
        _date = time.strftime('%Y-%m-%d',time.localtime(ts))
        _time = time.strftime('%X',time.localtime(ts))
        print(_date)
        print(_time)
        os.system(f'date -s "{_date} {_time}"')
        os.system('hwclock -w -u')
    except Exception as e:
        print("ntp server connected error!")
        pass

